using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Library.DataTier.Compiled;

namespace OR.Lazarus.Library.DataTier.Compiled.Lazarus
{
	/// <summary>
	/// Defines a single group of related data components.
	/// </summary>
   public class ProjectDetail : EntityBase
   {
		protected System.String mName;
		protected string mOwner;
		protected string mUser;
		protected string mDefaultNamespace;
		protected string mNamespacePrefix;
		protected string mNamespaceURI;
		protected string mBusinessConcept;
		protected string mDescription;
	
		protected Derived.DataSourceDetail mDataSource;
		protected Derived.SecurityDetail mSecurity;
	
		protected Derived.ObjectCollection mObjects;
		protected Derived.TableCollection mTables;
		protected Derived.PackageCollection mPackages;
		protected Derived.BusinessViewCollection mBusinessViews;

		public ProjectDetail()
		{
			mObjects = new Derived.ObjectCollection();
			mObjects.ParentEntity = this;
			mTables = new Derived.TableCollection();
			mTables.ParentEntity = this;
			mPackages = new Derived.PackageCollection();
			mPackages.ParentEntity = this;
			mBusinessViews = new Derived.BusinessViewCollection();
			mBusinessViews.ParentEntity = this;
	
			mDataSource = new Derived.DataSourceDetail();
			mDataSource.ParentEntity = this;
			mSecurity = new Derived.SecurityDetail();
			mSecurity.ParentEntity = this;
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Owner
		{
			get
			{
				return ( mOwner );
			}
			set
			{
				mOwner = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string User
		{
			get
			{
				return ( mUser );
			}
			set
			{
				mUser = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string DefaultNamespace
		{
			get
			{
				return ( mDefaultNamespace );
			}
			set
			{
				mDefaultNamespace = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string NamespacePrefix
		{
			get
			{
				return ( mNamespacePrefix );
			}
			set
			{
				mNamespacePrefix = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string NamespaceURI
		{
			get
			{
				return ( mNamespaceURI );
			}
			set
			{
				mNamespaceURI = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string BusinessConcept
		{
			get
			{
				return ( mBusinessConcept );
			}
			set
			{
				mBusinessConcept = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public Derived.DataSourceDetail DataSource
		{
			get
			{
				return ( mDataSource );
			}
			set
			{
				mDataSource = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public Derived.SecurityDetail Security
		{
			get
			{
				return ( mSecurity );
			}
			set
			{
				mSecurity = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public Derived.ObjectCollection Objects
		{
			get
			{
				return ( mObjects );
			}
			set
			{
				mObjects = value;
			}
		}

		public Derived.TableCollection Tables
		{
			get
			{
				return ( mTables );
			}
			set
			{
				mTables = value;
			}
		}

		public Derived.PackageCollection Packages
		{
			get
			{
				return ( mPackages );
			}
			set
			{
				mPackages = value;
			}
		}

		public Derived.BusinessViewCollection BusinessViews
		{
			get
			{
				return ( mBusinessViews );
			}
			set
			{
				mBusinessViews = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			mOwner = DataUtility.GetString( pSource, "owner" );
			mUser = DataUtility.GetString( pSource, "user" );
			mDefaultNamespace = DataUtility.GetString( pSource, "defaultnamespace" );
			mNamespacePrefix = DataUtility.GetString( pSource, "namespaceprefix" );
			mNamespaceURI = DataUtility.GetString( pSource, "namespaceuri" );
			mBusinessConcept = DataUtility.GetString( pSource, "businessconcept" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lzc:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			

			// FK Values
			XmlElement vDataSource = ( XmlElement )pSource.SelectSingleNode( "lzc:datasource", PersistenceConfig.Namespaces );
			
			if ( vDataSource != null )
			{
				mDataSource.LoadXml( vDataSource );
			}
			XmlElement vsecurity = ( XmlElement )pSource.SelectSingleNode( "lzc:security", PersistenceConfig.Namespaces );
			
			if ( vsecurity != null )
			{
				mSecurity.LoadXml( vsecurity );
			}
			XmlElement vObjects = ( XmlElement )pSource.SelectSingleNode( "lzc:objects", PersistenceConfig.Namespaces );
			
			if ( vObjects != null )
			{
				mObjects.LoadXml( vObjects );
			}
			XmlElement vTables = ( XmlElement )pSource.SelectSingleNode( "lzc:tables", PersistenceConfig.Namespaces );
			
			if ( vTables != null )
			{
				mTables.LoadXml( vTables );
			}
			XmlElement vPackages = ( XmlElement )pSource.SelectSingleNode( "lzc:packages", PersistenceConfig.Namespaces );
			
			if ( vPackages != null )
			{
				mPackages.LoadXml( vPackages );
			}
			XmlElement vBusinessViews = ( XmlElement )pSource.SelectSingleNode( "lzc:businessviews", PersistenceConfig.Namespaces );
			
			if ( vBusinessViews != null )
			{
				mBusinessViews.LoadXml( vBusinessViews );
			}
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lzc", "project", "http://schemas.icitadel.com/Lazarus/Compiled.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			if ( !String.IsNullOrEmpty( mOwner ) )
			{
				vNewElement.SetAttribute( "owner", mOwner );
			}
					
			if ( !String.IsNullOrEmpty( mUser ) )
			{
				vNewElement.SetAttribute( "user", mUser );
			}
					
			if ( !String.IsNullOrEmpty( mDefaultNamespace ) )
			{
				vNewElement.SetAttribute( "defaultnamespace", mDefaultNamespace );
			}
					
			if ( !String.IsNullOrEmpty( mNamespacePrefix ) )
			{
				vNewElement.SetAttribute( "namespaceprefix", mNamespacePrefix );
			}
					
			if ( !String.IsNullOrEmpty( mNamespaceURI ) )
			{
				vNewElement.SetAttribute( "namespaceuri", mNamespaceURI );
			}
					
			if ( !String.IsNullOrEmpty( mBusinessConcept ) )
			{
				vNewElement.SetAttribute( "businessconcept", mBusinessConcept );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lzc", "description", "http://schemas.icitadel.com/Lazarus/Compiled.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			// FK Values
			vNewElement.AppendChild( mDataSource.SaveXml( p_docContext ) );
			
			vNewElement.AppendChild( mSecurity.SaveXml( p_docContext ) );
			

			// Collections
			
			XmlElement	vCollection	= null;
			
			vCollection = mObjects.SaveXml( p_docContext );
			if ( vCollection != null )
			{
				vNewElement.AppendChild( vCollection );
			}
			
			vCollection = mTables.SaveXml( p_docContext );
			if ( vCollection != null )
			{
				vNewElement.AppendChild( vCollection );
			}
			
			vCollection = mPackages.SaveXml( p_docContext );
			if ( vCollection != null )
			{
				vNewElement.AppendChild( vCollection );
			}
			
			vCollection = mBusinessViews.SaveXml( p_docContext );
			if ( vCollection != null )
			{
				vNewElement.AppendChild( vCollection );
			}

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.ProjectDetail v_oReturn = new Derived.ProjectDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.Owner = mOwner;
			v_oReturn.User = mUser;
			v_oReturn.DefaultNamespace = mDefaultNamespace;
			v_oReturn.NamespacePrefix = mNamespacePrefix;
			v_oReturn.NamespaceURI = mNamespaceURI;
			v_oReturn.BusinessConcept = mBusinessConcept;
			v_oReturn.Description = mDescription;
			v_oReturn.DataSource = ( Derived.DataSourceDetail )mDataSource.Clone();
			v_oReturn.Security = ( Derived.SecurityDetail )mSecurity.Clone();
			
			// FK Values
			v_oReturn.DataSource = this.DataSource.CloneTyped();
			
			v_oReturn.Security = this.Security.CloneTyped();
			

			// Collections

			foreach ( Derived.ObjectDetail vDetail in mObjects )
			{
				v_oReturn.Objects.Add( vDetail.CloneTyped() );
			}

			foreach ( Derived.TableDetail vDetail in mTables )
			{
				v_oReturn.Tables.Add( vDetail.CloneTyped() );
			}

			foreach ( Derived.PackageDetail vDetail in mPackages )
			{
				v_oReturn.Packages.Add( vDetail.CloneTyped() );
			}

			foreach ( Derived.BusinessViewDetail vDetail in mBusinessViews )
			{
				v_oReturn.BusinessViews.Add( vDetail.CloneTyped() );
			}
			
			return ( v_oReturn );
		}

		public virtual Derived.ProjectDetail CloneTyped()
		{
			return ( ( Derived.ProjectDetail )this.Clone() );
		}
   }
}
   